<?php
    include 'template/header.html';
require_once 'lib/function.php';

    $action = isset($_GET['action'])?$_GET['action']:'list';
    switch ($action) {
        case 'list':

            $sql = "select * from caretype";
            $res = getAllData($sql);
            include 'template/care_type_list.html';

            break;
        case 'add':
            include 'template/care_type_add.html';
            break;
        case 'add_check':
            $method = isset($_POST['method'])?$_POST['method']:'';
            $info = isset($_POST['info'])?$_POST['info']:'';
            $sql = "select * from customerstat where cstat_stat = '$method'";
            $res = getRowNum($sql);
            if($res>0){
                echo "<script>alert('已有的关怀方式！');location.href='care_type.php?action=add'</script>";
            }
            $sql = "insert into caretype values('','$method','$info')";
            $res = dclData($sql);
            if($res){
                echo "<script>alert('添加成功!');location.href='care_type.php'</script>";
            }
            break;
        case 'delete':
            $ct_id = $_GET['ct_id'];
            $sql = "delete from caretype where ct_id='$ct_id'";
            $res = dclData($sql);
            if($res){
                echo "<script>alert('删除成功!');location.href='care_type.php'</script>";
            }
            break;
        case 'update':
            $ct_id = $_GET['ct_id'];
            $sql = "select * from caretype where ct_id='$ct_id'";
            $res = getAllData($sql);
            $res = $res[0];
            include 'template/care_type_add.html';
            break;
        case 'update_check':
            $ct_id = $_GET['ct_id'];
            $method = $_POST['method'];
            $info = $_POST['info'];
            $sql = "update caretype set ct_type='$method',ct_content='$info' where ct_id='$ct_id'";
            $res = dclData($sql);
            if($res){
                echo "<script>alert('更新成功!');location.href='care_type.php'</script>";
            }
            break;
    }
    include 'template/foot.html';